<div class="flexform">
    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'web-coupon-form',
        'enableAjaxValidation' => false
            ));
    ?>
    <div class="row">
        <?php echo $form->labelEx($model, 'game_id'); ?>
        <?php echo $form->dropDownList($model, 'game_id', array(0 => '不限') + ProductCategory::model()->getGameSelect()); ?>
        <?php echo $form->error($model, 'game_id', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'product_type'); ?>
        <?php echo $form->dropDownList($model, 'product_type', array('ALL' => '不限') + Yii::app()->params['model_array']); ?>
        <?php echo $form->error($model, 'product_type', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'min_money'); ?>
        <?php echo $form->textField($model, 'min_money', array('size' => 10, 'maxlength' => 10)); ?>
        <?php echo $form->error($model, 'min_money', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'coupon_type'); ?>
        <?php echo $form->dropDownList($model, 'coupon_type', $model->couponTypes); ?>
        <?php echo $form->error($model, 'coupon_type', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'coupon_value'); ?>
        <?php echo $form->textField($model, 'coupon_value', array('size' => 5, 'maxlength' => 8, 'class' => 'tip', 'title' => '打折: 原价 X (优惠额度/100), 抵现: 原价-优惠额度')); ?>
        <div style="line-height: 34px;font-size: 14px;">打折: 原价 X (优惠额度/100), 抵现: 原价 - 优惠额度</div>
        <?php echo $form->error($model, 'coupon_value', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'start_time'); ?>
        <?php
        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
            'name' => 'WebCoupon[start_time]',
            'language' => 'zh-cn',
            'value' => $model->start_time,
            // additional javascript options for the date picker plugin
            'options' => array(
                'dateFormat' => 'yy-mm-dd',
                
            ),
        ));
        ?>
        <?php echo $form->error($model, 'start_time', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'over_time'); ?>
        <?php
        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
            'name' => 'WebCoupon[over_time]',
            'language' => 'zh-cn',
            'value' => $model->over_time,
            // additional javascript options for the date picker plugin
            'options' => array(
                'dateFormat' => 'yy-mm-dd',
            )
        ));
        ?>
        <?php echo $form->error($model, 'over_time', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'use_num'); ?>
        <?php echo $form->textField($model, 'use_num'); ?> <div style="line-height: 34px;">-1表示不限制</div>
        <?php echo $form->error($model, 'use_num', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'uid'); ?>
        <?php echo $form->textField($model, 'uid', array('size' => 11, 'maxlength' => 11)); ?>
        <?php echo $form->error($model, 'uid', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'coupon'); ?>
        <?php echo $form->textField($model, 'coupon'); ?> <input onclick="setCoupon()" type="button" value="生成打折码" />
        <?php echo $form->error($model, 'coupon', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'status'); ?>
        <?php echo $form->dropDownList($model, 'status', $model->status_array); ?>
        <?php echo $form->error($model, 'status', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="action">
        <?php echo CHtml::submitButton($model->isNewRecord ? '创建' : '保存'); ?>
    </div>
    <?php $this->endWidget(); ?>
</div><!-- form -->
<div class="clear"></div>
<script>
    function setCoupon(){
        var coupon = "";
        coupon = $("#WebCoupon_product_type").val();
        coupon += "-" + getRndStr(5);
        if($("#WebCoupon_uid").val() != 0){
            coupon += "-U" + $("#WebCoupon_uid").val();
        }
        $("#WebCoupon_coupon").val(coupon);
    }
    function getRndStr(k)
    {
        var s=[];
        var a=parseInt(Math.random()*25)+(Math.random()>0.5?65:97);
        for (var i=0;i<k;i++){
            s[i]=Math.random()>0.5?parseInt(Math.random()*9):String.fromCharCode(parseInt(Math.random()*25)+(Math.random()>0.5?65:97)).toUpperCase();
        }
        return s.join("");
    }
</script>